<?php
declare (strict_types=1);

namespace Plugin\Message\Model;

use Hyperf\Database\Model\Relations\HasMany;
use Mine\MineModel;
use Plugin\Message\Enums\MessageTypeEnum;

class Message extends MineModel
{
    /**
     * The table associated with the model.
     *
     * @var string|null
     */
    protected ?string $table = 'rd_message';
    
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected array $fillable = [
        'id', 'type', 'title', 'content', 'extra', 'related_id', 'level', 'created_at', 'updated_at', 'deleted_at'
    ];
    
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected array $casts = [
        'id' => 'integer',
        'type' => 'integer',
        'related_id' => 'integer',
        'level' => 'integer',
        'extra' => 'array',
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
        'deleted_at' => 'datetime',
    ];
    
    /**
     * 读取状态关联
     */
    public function reads(): HasMany
    {
        return $this->hasMany(MessageRead::class, 'message_id', 'id');
    }

}